package com.example.seh.home.substitution;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.fonts.Font;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.TextView;

import com.example.seh.R;
import com.example.seh.util.BackUtil;

public class CourierSuccessActivity extends AppCompatActivity {
    private TextView code, num;
    private int count;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_courier_success);
        getViews();
        getActivityDatas();
    }

    private void getActivityDatas() {
        Intent intent = getIntent();
        DeliverDTO deliverDTO = (DeliverDTO) intent.getSerializableExtra("couriers");
        code.setText(deliverDTO.getDeliverCode());

        new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 5; i >= 0; i--) {
                    count = i;
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (count > 0) {
                                num.setText(count + "");
                            } else {
                                finish();
                            }

                        }
                    });
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    private void getViews() {
        code = findViewById(R.id.code);
        num = findViewById(R.id.courier_success_num);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            BackUtil.backToMain(CourierSuccessActivity.this);
        }
        return false;
    }
}